﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class UserProcessBatSOX : UserControl
    {
        public UserProcessBatSOX()
        {
            InitializeComponent();
            m_foreColor = Color.Black;
            m_foreFont = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
            batBase1.chargeBubbleSpeed = 0;
            batBase1.chargeBubbleIntervalTime = 100;
            batBase1.Height = (int)((double)m_value / (double)m_maxValue * this.Height) + batBase1.BatBaseHeight;
            this.batBase1.OnPainted += ucBatBase1_Painted;
            this.batBase1.BatBaseState = false;
        }



        [Description("值变更事件"), Category("自定义")]
        public event EventHandler ValueChanged;

        int m_value = 0;
        [Description("当前属性"), Category("自定义")]
        public int Value
        {
            set
            {
                if (value > m_maxValue)
                    m_value = m_maxValue;
                else if (value < 0)
                    m_value = 0;
                else
                    m_value = value;
                if (ValueChanged != null)
                    ValueChanged(this, null);
                batBase1.Height = (int)((double)m_value / (double)m_maxValue * this.Height) + batBase1.BatBaseHeight;
                Refresh();
            }
            get
            {
                return m_value;
            }
        }
        [Description("是否动态"), Category("自定义")]
        public bool IsDynamicState
        {
            get { return this.batBase1.BatBaseState; }
            set
            {

                this.batBase1.BatBaseState = value;
                if (value)
                {
                    this.batBase1.chargeBubbleSpeed = 10;   
                }
                else
                {
                    this.batBase1.chargeBubbleSpeed = 0;
                }
            }
        }

        private int m_maxValue = 100;
        [Description("最大值"), Category("自定义")]
        public int MaxValue
        {
            get { return m_maxValue; }
            set
            {
                if (value < m_value)
                    m_maxValue = m_value;
                else
                    m_maxValue = value;
                Refresh();
            }
        }
        Color m_foreColor;
        Font m_foreFont;

        [Description("进度字体"), Category("自定义")]
        public  Font foreFont
        {
            get
            {
                return m_foreFont;
            }
            set
            {
                m_foreFont = value;
            }
        }
        [Description("进度颜色"), Category("自定义")]
        public  Color ForeColor
        {
            get
            {
                return m_foreColor;
            }
            set
            {
                m_foreColor = value;
            }
        }
        [Description("值颜色"), Category("自定义")]
        public Color ValueColor
        {
            get { return this.batBase1.BatBaseColor; }
            set
            {
                this.batBase1.BatBaseColor = value;
            }
        }

        [Description("充电气泡速度（0表示不启用）"), Category("自定义")]
        public int BubbleSpeed
        {
            get { return this.batBase1.chargeBubbleSpeed; }
            set { this.batBase1.chargeBubbleSpeed = value; }
        }


        [Description("充电气泡生成间隔时间(毫秒)"), Category("自定义")]
        public int chargeBubbleIntervalTime
        {
            get { return this.batBase1.chargeBubbleIntervalTime; }
            set { this.batBase1.chargeBubbleIntervalTime = value; }
        }


        /// <summary>
        /// Handles the Painted event of the ucBatBase1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PaintEventArgs" /> instance containing the event data.</param>
        void ucBatBase1_Painted(object sender, PaintEventArgs e)
        {
            string strValue = ((double)m_value / (double)m_maxValue).ToString("0.%");
            System.Drawing.SizeF sizeF = e.Graphics.MeasureString(strValue, m_foreFont);
            e.Graphics.DrawString(strValue, m_foreFont, new SolidBrush(m_foreColor), new PointF((this.Width - sizeF.Width) / 2, (this.batBase1.Height - this.Height) + (this.Height - sizeF.Height) / 2));
        }
        /// <summary>
        /// Handles the <see cref="E:Paint" /> event.
        /// </summary>
        /// <param name="e">The <see cref="PaintEventArgs" /> instance containing the event data.</param>
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            string strValue = ((double)m_value / (double)m_maxValue).ToString("0.%");
            System.Drawing.SizeF sizeF = e.Graphics.MeasureString(strValue, m_foreFont);
            e.Graphics.DrawString(strValue, m_foreFont, new SolidBrush(m_foreColor), new PointF((this.Width - sizeF.Width) / 2, (this.Height - sizeF.Height) / 2 + 1));

        }

        private void InitializeComponent()
        {
            this.batBase1 = new UserControls_BatBase.BatBase();
            this.SuspendLayout();
            // 
            // batBase1
            // 
            this.batBase1.BatBaseColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(77)))), ((int)(((byte)(59)))));
            this.batBase1.BatBaseHeight = 10;
            this.batBase1.BatBaseSleep = 50;
            this.batBase1.BatBaseState = false;
            this.batBase1.BatBaseWidth = 500;
            this.batBase1.chargeBubbleIntervalTime = 500;
            this.batBase1.chargeBubbleSpeed = 0;
            this.batBase1.Dock = System.Windows.Forms.DockStyle.Bottom;
            this.batBase1.Location = new System.Drawing.Point(0, 125);
            this.batBase1.Name = "batBase1";
            this.batBase1.Size = new System.Drawing.Size(150, 25);
            this.batBase1.TabIndex = 0;
            this.batBase1.Text = "batBase1";
            // 
            // UserProcessBatSOX
            // 
            this.Controls.Add(this.batBase1);
            this.Name = "UserProcessBatSOX";
            this.ResumeLayout(false);

        }
    }
}
